﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApFLEXPointCloudLayerValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Flexibles;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands;

public class CApFLEXPointCloudLayerValidator : ITxValidator
{
  internal CApFLEXPointCloudLayerValidator()
  {
  }

  public ITxObject GetObject(string text)
  {
    ITxObject itxObject1 = (ITxObject) null;
    if (text != null && text.Length > 0)
    {
      TxObjectList objectsByName = TxApplication.ActiveDocument.GetObjectsByName(text);
      if (objectsByName != null && ((Collection<ITxObject>) objectsByName).Count > 0)
      {
        string errorMessage = (string) null;
        foreach (ITxObject itxObject2 in (Collection<ITxObject>) objectsByName)
        {
          if (this.IsValidObject(itxObject2, out errorMessage))
          {
            itxObject1 = itxObject2;
            break;
          }
        }
      }
    }
    return itxObject1;
  }

  public string GetText(ITxObject obj)
  {
    string text = (string) null;
    try
    {
      text = obj.Name;
    }
    catch (Exception ex)
    {
    }
    return text;
  }

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    errorMessage = obj is ITxPointCloudLayer ? (string) null : string.Format(CApFLEXStringTable.SelectedPointCloudLayerIsNotPointCloudLayerObjectMessage, (object) (this.GetText(obj) ?? string.Empty));
    return errorMessage == null;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    errorMessage = (string) null;
    bool flag = text == string.Empty || this.GetObject(text) != null;
    if (!flag)
      errorMessage = !this.DoesObjectWithGivenNameExist(text) ? CApFLEXStringTable.InvalidPointCloudLayerNameMessage : string.Format(CApFLEXStringTable.InvalidPointCloudLayer, (object) text);
    return flag;
  }

  private bool DoesObjectWithGivenNameExist(string name)
  {
    bool flag = false;
    if (name != null && name.Length > 0)
    {
      TxObjectList objectsByName = TxApplication.ActiveDocument.GetObjectsByName(name);
      flag = objectsByName != null && ((IEnumerable<ITxObject>) objectsByName).Any<ITxObject>();
    }
    return flag;
  }
}
